package com.itheima.service.db.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.Question;
import com.itheima.mapper.db.QuestionMapper;
import com.itheimma.service.db.QuestionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionServiceImpl implements QuestionService {

    //由于此时已经不是主键了，所以需要设置查询条件

    @Autowired
    private QuestionMapper questionMapper;

    //查
    @Override
    public Question findById(Long userId) {
        QueryWrapper<Question> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        return questionMapper.selectOne(qw);
    }

    //存
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    //更新
    @Override
    public void update(Question question) {
        /*先查question，如果有值，就更新，此时因为查询已经有了对应的主键了*/
        questionMapper.updateById(question);
    }
}
